package com.aispeech.asr.apis.ssc.callback;

import java.io.IOException;

import com.aispeech.asr.apis.ssc.websocket.connection.EmitterManager;
import com.aispeech.jarpc.ArpcException;
import com.aispeech.jarpc.IArpcCallback;
import com.aispeech.jarpc.TextBin;
import com.aispeech.jarpc.message.ArpcMessage;

import lombok.extern.slf4j.Slf4j;


@Slf4j
public class VadOnlineCallback implements IArpcCallback {

    private EmitterManager manager;
    private String clientSessionId;
	
    public VadOnlineCallback(String clientSessionId, EmitterManager manager) {
    	this.manager = manager;
    	this.clientSessionId = clientSessionId;
    }
	
	@Override
	public void onArpcMessage(ArpcMessage message) {
		try {
			TextBin textBin = TextBin.from(message.getBody());
			manager.doSpeakerDiarisation(clientSessionId, textBin);
		} catch (Exception e) {
			log.error("[VadOnlineCallback] failed sessionId:{}",clientSessionId,e);
		}
	}
	
	@Override
	public void onArpcError(ArpcException exception) {
		
		log.error("[VadOnlineCallback onArpcError]",exception);
		manager.doErrorResponse(clientSessionId, exception);
		
	}

}
